unit App.Action.TAppCustomeAction;

interface

uses SmallStruct.Action,
  SmallStruct.Action.TSSAction,
  SmallStruct.Model,
  SmallStruct.Configuration;

type
  TAppCustomeAction = class(TSSAction)
  protected
    function GetRequestViewPrimaryModel: ISSModel;
    function GetRequestViewPrimaryDataModel: ISSDataModel;
    function GetRequestViewModel(const AModelName: string): ISSModel;
    function GetRequestViewDataModel(const AModelName: string): ISSDataModel;
    function GetRequestViewConfiguration: ISSViewConfiguration;
    function GetResponseViewPrimaryModel: ISSModel;
    function GetResponseViewPrimaryDataModel: ISSDataModel;
    function GetResponseViewModel(const AModelName: string): ISSModel;
    function GetResponseViewDataModel(const AModelName: string): ISSDataModel;
    function GetResponseViewConfiguration: ISSViewConfiguration;
  end;

implementation

{ TAppCustomeAction }

function TAppCustomeAction.GetRequestViewConfiguration: ISSViewConfiguration;
begin
  Result := (GetContext as ISSActionContext).GetRequestView.GetContext.GetConfiguration as ISSViewConfiguration;
end;

function TAppCustomeAction.GetRequestViewDataModel(const AModelName: string): ISSDataModel;
begin
  Result := nil;

  if (GetContext as ISSActionContext).GetRequestView.GetModelContainer.FindObject(AModelName) >= 0 then
    Result := (GetContext as ISSActionContext).GetRequestView.GetModelContainer.GetObject(AModelName) as ISSDataModel
  else if (GetContext as ISSActionContext).GetRequestView.GetContext.GetParameter.FindObject(AModelName) >= 0 then
    Result := (GetContext as ISSActionContext).GetRequestView.GetContext.GetParameter.GetObject(AModelName) as ISSDataModel;
end;

function TAppCustomeAction.GetRequestViewModel(const AModelName: string): ISSModel;
begin
  Result := nil;

  if (GetContext as ISSActionContext).GetRequestView.GetModelContainer.FindObject(AModelName) >= 0 then
    Result := (GetContext as ISSActionContext).GetRequestView.GetModelContainer.GetObject(AModelName) as ISSModel
  else if (GetContext as ISSActionContext).GetRequestView.GetContext.GetParameter.FindObject(AModelName) >= 0 then
    Result := (GetContext as ISSActionContext).GetRequestView.GetContext.GetParameter.GetObject(AModelName) as ISSModel;
end;

function TAppCustomeAction.GetRequestViewPrimaryDataModel: ISSDataModel;
begin
  Result := GetRequestViewDataModel(GetRequestViewConfiguration.GetPrimaryModelName);
end;

function TAppCustomeAction.GetRequestViewPrimaryModel: ISSModel;
begin
  Result := GetRequestViewModel(GetRequestViewConfiguration.GetPrimaryModelName);
end;

function TAppCustomeAction.GetResponseViewConfiguration: ISSViewConfiguration;
begin
  Result := (GetContext as ISSActionContext).GetResponseView.GetContext.GetConfiguration as ISSViewConfiguration;
end;

function TAppCustomeAction.GetResponseViewDataModel(const AModelName: string): ISSDataModel;
begin
  Result := (GetContext as ISSActionContext).GetResponseView.GetModelContainer.GetObject(AModelName) as ISSDataModel;
end;

function TAppCustomeAction.GetResponseViewModel(const AModelName: string): ISSModel;
begin
  Result := (GetContext as ISSActionContext).GetResponseView.GetModelContainer.GetObject(AModelName) as ISSModel;
end;

function TAppCustomeAction.GetResponseViewPrimaryDataModel: ISSDataModel;
begin
  Result := GetResponseViewDataModel(GetResponseViewConfiguration.GetPrimaryModelName);
end;

function TAppCustomeAction.GetResponseViewPrimaryModel: ISSModel;
begin
  Result := GetRequestViewModel(GetResponseViewConfiguration.GetPrimaryModelName);
end;

end.
